package com.example.administrator.newproject;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;


public class BeforeMainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_before_main);
        getSupportActionBar().hide();

        findViewById(R.id.button_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(BeforeMainActivity.this,MainActivity.class);
                startActivity(intent);


            }
        });

    }
    long currnttime=0;

    @Override
    public void onBackPressed() {

        if (System.currentTimeMillis()-currnttime<3000){

            Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);

            System.exit(0);//退出程序

        }else{

            currnttime=System.currentTimeMillis();
            Toast.makeText(BeforeMainActivity.this, "再按一次退出!", Toast.LENGTH_SHORT).show();

        }

    }

}
